use std::env;

use ipc_channel::{ipc, ipc::IpcOneShotServer};

fn main() {
    let args: Vec<String> = env::args().collect();

    if args.len() < 2 {
        eprintln!("用法: child <server_name>");
        return;
    }

    let server_name = &args[1];

    let tx: ipc::IpcSender<String> =
        ipc::IpcSender::connect(server_name.to_string()).expect("连接主通道失败");

    for i in 0..10 {
        let msg = format!("主消息 {}", i);
        let _ = tx.send(msg.clone()).expect("发送消息失败");
        println!("[子进程] 发送: {}", msg);
    }

    std::thread::sleep(std::time::Duration::from_secs(3));

    println!("[子进程] 退出");
}
